package com.busibuilding.administrate.area.action;

import java.util.List;

import org.displaytag.tags.TableTagParameters;

import com.busibuilding.administrate.area.service.ProvinceService;
import com.busibuilding.administrate.area.vo.ProvinceCVO;
import com.busibuilding.common.action.CommonActionImpl;
import com.busibuilding.utils.StringUtil;
/**
 * Class Name: ProvinceAction.java
 * Description: 
 * @author Lin Yanjun
 * @version 1.0
 * @since 1.0
 * Date: 2010-2-25
 */
public class ProvinceAction extends CommonActionImpl {
	/**
	 * 
	 */
	private static final long serialVersionUID = 864872582501542562L;
	
	private int page;
	private int currentPage;
	private String defunctInd;
	
	private String provinceCd;
	private String provinceName;
	
	private ProvinceService service;

	public String search() throws Exception{
		ProvinceCVO provinceCVO = new ProvinceCVO();
		if(StringUtil.isNotEmpty(defunctInd)){
			provinceCVO.setDefunctInd(defunctInd);
		}else{
			provinceCVO.setDefunctInd("N");
		}
		if(StringUtil.isNotEmpty(provinceCd)){
			provinceCVO.setProvinceCd(provinceCd.toUpperCase());
		}
		if(StringUtil.isNotEmpty(provinceName)){
			provinceCVO.setProvinceName(provinceName);
		}
		provinceCVO.setMinIndex((getPage()-1)*10);
		provinceCVO.setMaxIndex(getPage()*10);
		int listSize = service.getRecordsCount(provinceCVO);
		List<ProvinceCVO> resultList = service.searchProvince(provinceCVO);
		this.getRequest().setAttribute("provinceListSize", listSize);
		this.getRequest().setAttribute("provinceDisplayList", resultList);
		return INPUT;
	}
	
	public int getPage() {
		if (getRequest().getParameter(TableTagParameters.SORT_AMOUNT_PAGE) == null || "".equals(getRequest().getParameter(TableTagParameters.SORT_AMOUNT_PAGE))) {
        	page = currentPage;
        }else{
        	page = Integer.parseInt(getRequest().getParameter(TableTagParameters.SORT_AMOUNT_PAGE));
        }
		
		if (page == 0){
			page = DEFAULT_PAGE;
		}
		
		return page;
	}

	public void setPage(int page) {
		if (page > 0){
			this.page = page;
		}
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public String getDefunctInd() {
		return defunctInd;
	}

	public void setDefunctInd(String defunctInd) {
		this.defunctInd = defunctInd;
	}

	public String getProvinceCd() {
		return provinceCd;
	}

	public void setProvinceCd(String provinceCd) {
		this.provinceCd = provinceCd;
	}

	public String getProvinceName() {
		return provinceName;
	}

	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}
	
	public void setService(ProvinceService service) {
		this.service = service;
	}

}
